package org.example.controller;


import org.example.exception.BusinessException;
import org.example.exception.SystemException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

//异常拦截器
@RestControllerAdvice
public class ProjectExceptionAdvice {

    @ExceptionHandler(BusinessException.class)
    public Result doBusinessException(BusinessException e){
        return new Result(e.getCode(),null,e.getMessage());
    }

    @ExceptionHandler(SystemException.class)
    public Result doSystemException(SystemException e){
        //记录日志（错误堆栈）
        //发送邮件给开发人员
        //发送短信给运维人员
        return new Result(e.getCode(),null,e.getMessage());
    }

    //定义处理是哪种异常
    @ExceptionHandler(Exception.class)
    public Result doException(Exception e){
        //记录日志（错误堆栈）
        //发送邮件给开发人员
        //发送短信给运维人员
        return new Result(Code.SYSTEM_UNKNOW_ERR,null,"系统繁忙，请联系管理员");
    }
}
